#include "common.h"
#define API_MAX_STREAMCB 10

static APISendVideoStreamCbFun SendStreamfunc[API_MAX_STREAMCB];


ProtocolAPIHandle_T* GetProtocolAPIHandle()
{
	static  ProtocolAPIHandle_T handle = {0};
	return &handle;
}

int InitProtocolAPIHandle()
{
	 ProtocolAPIHandle_T *handle =  GetProtocolAPIHandle();
	 memset(handle,0,sizeof(ProtocolAPIHandle_T));
	 memset(SendStreamfunc,0,sizeof(SendStreamfunc));
	 return KEY_TRUE;
}

int SetProtocolAPIHandle(ProtocolAPIHandle_T *handle) 
{
	ProtocolAPIHandle_T *SysHandle = GetProtocolAPIHandle();
	if(handle == NULL || SysHandle == NULL){
		return KEY_FALSE;
	}
	memcpy(SysHandle,handle,sizeof(ProtocolAPIHandle_T));
	return KEY_TRUE;
}

int RegisterAPISendVideoStream(APISendVideoStreamCbFun func)
{
	int i = 0;
	for(i = 0;i < API_MAX_STREAMCB;i++){
		if(SendStreamfunc[i] == NULL){
			SendStreamfunc[i] = func;
			break;
		}
	}
	return KEY_TRUE;
}

int ProtocolAPISendVideoStream(VideoFrameInfo_T *streamInfo)
{
	int i = 0;
	for(i = 0;i < API_MAX_STREAMCB;i++){
		//DF_DEBUG("%d",SendStreamfunc[i]);
		if(SendStreamfunc[i] == NULL){
			break;
		}
		SendStreamfunc[i](streamInfo);
	}
	return KEY_TRUE;
}
